<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="./OL_SDK/include-openlayers-local.js"></script>
    <script src="./libs/gaode.js"></script>
    <script src="./utils/createDraw.js"></script>
    <script src="./utils/Query.js"></script>
</head>

<body>
    <button onclick="queryByDraw()">测试-查询</button>
    <div id="map">
    </div>
    <script>
        var docLayer = new Zondy.Map.Doc("", "zxd-plus-pla", {

        })
        var map = new ol.Map({
            target: "map",
            layers: [gaode, docLayer],
            view: new ol.View({
                projection: 'EPSG:4326',
                center: [114.30, 30.50],
                zoom: 4
            })
        })
        /* 获取画笔geometry */
        let source = new ol.source.Vector({

        })
        let layer = new ol.layer.Vector({
            source
        })
        map.addLayer(layer)
        function queryByDraw() {
            let draw = createDraw({
                type: "Box",
                source
            })
            map.addInteraction(draw)
            draw.on("drawend", handleDraw)
        }
        function handleDraw(evt) {
            var geometry = evt.feature.getGeometry();
            console.log(geometry)
            let service = {
                name: "zxd-plus-pla",
                layerId: 2
            }
            /* 2、调用查询方法获取要素 */
            Query.queryByGeom({
                geometry,
                service,
                callback: handleQuery
            })
        }

        function handleQuery(result) {
            // console.log(result)
            var format = new Zondy.Format.PolygonJSON();
            //将MapGIS要素JSON反序列化为ol.Feature类型数组
            var features = format.read(result);
            console.log(features)
        }
    </script>
</body>

</html>